module;
#include <string>
#include <thread>


export module Code_2_1_4;

void open_document_and_display_gui(std::string const& filename) {}

bool done_editing() { return true; }

enum class command_type : int {
	open_new_document
};

struct user_command {
	command_type type;
	user_command()
		: type{ command_type::open_new_document }
	{}
};

user_command get_user_input() {
	return user_command();
}

auto get_filename_from_user() -> std::string {
	return "foo.doc";
}

auto process_user_input(user_command const& cmd) -> void {}

export
namespace Code_2_1_4 {
	auto edit_document(std::string const& filename) -> void {
		open_document_and_display_gui(filename);
		while (!done_editing()) {
			user_command cmd = get_user_input();
			if (cmd.type == command_type::open_new_document) {
				std::string const new_name = get_filename_from_user();
				std::thread t{ edit_document, new_name };
				t.detach();
			}
			else {
				process_user_input(cmd);
			}

		}
	}
}